package demo2.demo2.controller;

import demo2.demo2.mapper.TeacherMapper;
import demo2.demo2.pojo.Teacher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class Controller {
    @Autowired
    private TeacherMapper teacherMapper;

    @GetMapping("/getTeachers")
    public List<Teacher> getTeachers(){
        return teacherMapper.getTeachers();
    }

    @GetMapping("/getTeacherById/{id}")
    public Teacher getTeacher(@PathVariable("id") Integer id){
        return  teacherMapper.getTeacher(id);
    }

    @GetMapping("/addTeacher")
    public int addTeacher(){
        Teacher  teacher = new Teacher();
        teacher.setName("嘟嘟");
        teacher.setId(5);
        return teacherMapper.addTeacher(teacher);
    }

    @GetMapping("/updateTeacher/{id}")
    public int updateTeacher(@PathVariable("id") int id){
        Teacher  teacher = new Teacher();
        teacher.setName("芜湖");
        teacher.setId(id);
        return  teacherMapper.updateTeacher(teacher);
    }

        @GetMapping("/deleteTeacher/{id}")
    public int deleteTeacher(@PathVariable("id") Integer id){
        return teacherMapper.deleteTeacher(id);
    }






}
